package com.dhcc.bpm.modules.safe.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.safe.entity.AppControl;
import com.dhcc.bpm.modules.safe.service.IAppControlService;
import com.dhcc.bpm.modules.safe.vo.AppControlVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @ClassName AppControlController
 * @Description  API访问控制渠道关联表 控制器
 * @Author daina
 * @Date 2020/2/21 14:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@RestController
@AllArgsConstructor
@RequestMapping("bpm-safe/appcontrol")
@Api(value = "API访问控制渠道关联表", tags = "API访问控制渠道关联表接口")
public class AppControlController extends BladeController {

	private IAppControlService appControlService;

	/**
	 * @Description 详情
	 * @Author daina
	 * @Date 21:30 2020/2/21
	 * @param appControl
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.safe.entity.AppControl>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiLog("详情")
	@ApiOperation(value = "详情", notes = "传入appControl")
	@Log(title = "详情",businessType = BusinessType.SELECT)
	public R<AppControl> detail(AppControl appControl) {
		AppControl detail = appControlService.getOne(Condition.getQueryWrapper(appControl));
		return R.data(detail);
	}

	/**
	 * @Description 分页 API访问控制渠道关联表
	 * @Author daina
	 * @Date 21:30 2020/2/21
	 * @param appControl
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.safe.entity.AppControl>>
	 **/
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入appControl")
	@ApiLog("查询")
	@Log(title = "查询",businessType = BusinessType.SELECT)
	public R<IPage<AppControl>> list(AppControl appControl, Query query) {
		IPage<AppControl> pages = appControlService.page(Condition.getPage(query), Condition.getQueryWrapper(appControl));
		return R.data(pages);
	}

	/**
	 * @Description 自定义分页 API访问控制渠道关联表
	 * @Author daina
	 * @Date 21:30 2020/2/21
	 * @param appControl
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.safe.vo.AppControlVO>>
	 **/
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入appControl")
	@ApiLog("查询")
	@Log(title = "查询",businessType = BusinessType.SELECT)
	public R<IPage<AppControlVO>> page(AppControlVO appControl, Query query) {
		IPage<AppControlVO> pages = appControlService.selectAppControlPage(Condition.getPage(query), appControl);
		return R.data(pages);
	}

	/**
	 * @Description 新增 API访问控制渠道关联表
	 * @Author daina
	 * @Date 21:30 2020/2/21
	 * @param appControl
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入appControl")
	@ApiLog("新增")
	@Log(title = "新增",businessType = BusinessType.INSERT)
	public R save(@Valid @RequestBody AppControl appControl) {
		return R.status(appControlService.save(appControl));
	}

	/**
	 * @Description 修改 API访问控制渠道关联表
	 * @Author daina
	 * @Date 21:30 2020/2/21
	 * @param appControl
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入appControl")
	@ApiLog("修改")
	@Log(title = "修改",businessType = BusinessType.UPDATE)
	public R update(@Valid @RequestBody AppControl appControl) {
		return R.status(appControlService.updateById(appControl));
	}

	/**
	 * @Description 新增或修改 API访问控制渠道关联表
	 * @Author daina
	 * @Date 21:31 2020/2/21
	 * @param appControl
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入appControl")
	@ApiLog("修改")
	@Log(title = "修改",businessType = BusinessType.UPDATE)
	public R submit(@Valid @RequestBody AppControl appControl) {
		return R.status(appControlService.saveOrUpdate(appControl));
	}

	
	/**
	 * @Description 删除 API访问控制渠道关联表
	 * @Author daina
	 * @Date 21:31 2020/2/21
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	@ApiLog("删除")
	@Log(title = "删除",businessType = BusinessType.DELETE)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(appControlService.removeByIds(Func.toLongList(ids)));
	}

	
}
